home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
varia
/
egebook.lha
/
ege.book
/
3
/
virtualbase.C
< prev
Wrap
C/C++ Source or Header
|
1992-06-05
|
2KB
|
89 lines
#include <stdio.h>
#include "bool.h"
// Class definition for Person
class Person {
char* name;
public:
Person(); // constructor
Person(char *n); // bodies declared elsewhere
void print(); // member function
};
// Body for class Person
Person::Person(){ // constructor
name = "";
}
Person::Person(char *n){ // constructor
name = n;
};
void Person::print(){ // member functions
printf("my name is: %s \n", name);
};
// Class definition for Teacher
// Teacher is derived
class Teacher: public Person { // from Person
int courses;
static int MaxCourses;
public:
Teacher(char *name):Person(name){
courses = 0;
}
bool check();
void addCourse();
};
// Body for class Teacher
int Teacher::MaxCourses = 2;
bool Teacher::check(){
return (bool) (courses < MaxCourses);
}
void Teacher::addCourse() {
if (check())
courses++;
}
class Researcher: public Person {
char *expertise; // field of expertise
public:
Researcher(char *e, char *n):Person(n){ // constructor
expertise = e;
}
void print(){
printf("I am an expert in: %s\n", expertise);
}
};
class Professor: public Teacher, public Researcher {
enum nature {teacher, researcher} kind;
public:
// combined constructor
Professor(char *name, char* exp):
Teacher(name),Researcher(exp,name){};
void change(){ // change nature
if (kind == teacher)
kind = researcher;
else
kind = teacher;
}
void print(){ // print according to nature
Teacher::print();
if (kind == researcher) {
printf("and ");
Researcher::print();
}
}
};
main(){
Professor p("John Prof","something");
p.print();
}